﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PortConfigView.xaml.cs" company="R.V.Kasner">
//   Copyright © 2011 R.V.Kasner
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Owen.Terminal.View
{
    using System;

    using Owen.Terminal.ViewModel;

    public partial class PortConfigView : IPortConfigView
    {
        private bool isSelected;

        public PortConfigView()
        {
            this.InitializeComponent();
        }

        public event Action Selected;

        public IPortConfigViewModel ViewModel
        {
            get
            {
                return this.DataContext as IPortConfigViewModel;
            }

            set
            {
                if (this.DataContext == value)
                {
                    return;
                }

                this.DataContext = value;
            }
        }

        IViewModel IView.ViewModel
        {
            get
            {
                return this.ViewModel;
            }

            set
            {
                this.ViewModel = value as IPortConfigViewModel;
            }
        }

        public bool IsSelected
        {
            get
            {
                return this.isSelected;
            }

            set
            {
                this.isSelected = value;
                if (this.isSelected)
                {
                    this.RaiseSelected();
                }
            }
        }

        public string Title
        {
            get
            {
                return "Порт";
            }
        }

        private void RaiseSelected()
        {
            var header = this.Selected;
            if (header != null)
            {
                header();
            }
        }
    }
}